//生成流水单子
export function $orderNumber() {
    var now = new Date()
    var month = now.getMonth() + 1
    var day = now.getDate()
    var hour = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    // month = now.setMonth(month)
    month = month.toString().padStart(2, '0')
    day = day.toString().padStart(2, '0')
    // hour = now.setHours(hour)
    hour = hour.toString().padStart(2, '0')

    // minutes = now.setMinutes(minutes)
    minutes = minutes.toString().padStart(2, '0')
    // seconds = now.setSeconds(seconds)
    seconds = seconds.toString().padStart(2, '0')
    var time = now.getFullYear().toString() + month + day + hour + minutes + seconds
    return (time + (Math.floor((Math.random() * 1000000)).toString()).padStart(6, '9'))
}
// 格式化时间
export function formatDate(value) {
    if (!value) {
        return 0
    }
    let dt = new Date(value);
    let years = dt
        .getFullYear()
        .toString()
        .padStart(2, 0);
    let month = (dt.getMonth() + 1).toString().padStart(2, 0);
    let date = dt
        .getDay()
        .toString()
        .padStart(2, 0);
    let hours = dt
        .getHours()
        .toString()
        .padStart(2, 0);
    let minutes = dt
        .getMinutes()
        .toString()
        .padStart(2, 0);
    let seconds = dt
        .getSeconds()
        .toString()
        .padStart(2, 0);
    // return `${years}-${month}-${date} ${hours}:${minutes}:${seconds}`;
    return `${years}-${month}-${date} ${hours}:${minutes}`;
}

// 设置分享到朋友
export function shareFrend(vm, option) {
    vm.$nextTick(() => {
        wx.ready(function () {
            //需在用户可能点击分享按钮前就先调用
            if (option) {
                wx.updateAppMessageShareData(option);
            } else {
                wx.updateAppMessageShareData({
                    title: "مارس كىنوخانىسدىكى ئەڭ  يېڭى سۈزۈك فىلىملەر سىزنىڭ كۆرۈشىڭىزنى ساقلاۋاتىدۇ", // 分享标题
                    desc: "بۇيەرنى بېسىپ كۆرۈڭ", // 分享描述
                    link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: 'https://mars-kino.oss-cn-beijing.aliyuncs.com/salon/share_img.jpg', // 分享图标
                    success: function () {}
                })
            }
        });
    });
}
// 设置分享到朋友圈
export function shareMoments(vm, option) {
    vm.$nextTick(() => {
        wx.ready(function () {
            //需在用户可能点击分享按钮前就先调用
            if (option) {
                wx.onMenuShareTimeline(option);
            } else {
                wx.onMenuShareTimeline({
                    title: "مارس كىنوخانىسدىكى ئەڭ  يېڭى سۈزۈك فىلىملەر سىزنىڭ كۆرۈشىڭىزنى ساقلاۋاتىدۇ", // 分享标题
                    desc: "بۇيەرنى بېسىپ كۆرۈڭ", // 分享描述
                    link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: 'https://mars-kino.oss-cn-beijing.aliyuncs.com/salon/share_img.jpg', // 分享图标
                    success: function () {
                        // 设置成功
                    }
                })
            }
        });
    });
}

export function throttle(fn, delay) {
    var lastTime;
    var timer;
    var delay = delay || 200;
    return function () {
        var args = arguments;
        // 记录当前函数触发的时间
        var nowTime = Date.now();
        if (lastTime && nowTime - lastTime < delay) {
            clearTimeout(timer);
            timer = setTimeout(function () {
                // 记录上一次函数触发的时间
                lastTime = nowTime;
                // 修正this指向问题
                fn.apply(this, args);
            }, delay);
        } else {
            lastTime = nowTime;
            fn.apply(this, args);
        }
    }
}
// 获取参数
export function getQueryVariable(urlStr) {
    try {
        if (typeof urlStr == "undefined") {
            var url = decodeURI(location.search); //获取url中"?"符后的字符串
        } else {
            var url = "?" + urlStr.split("?")[1];
        }
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            let strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    } catch (error) {
        return {}
    }
}